package com.cskaoyan.wordmemorize.controller.admin;

import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.DeleteGoodsOperateDTO;
import com.cskaoyan.wordmemorize.dto.admin.GoodsDTO;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.request.BatchDeleteCommand;
import com.cskaoyan.wordmemorize.request.GoodsCommand;
import com.cskaoyan.wordmemorize.request.PageRequest;
import com.cskaoyan.wordmemorize.service.GoodsService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "商品相关功能")
@RestController
@RequestMapping("/admin/goods")
public class GoodsController {
    @Resource
    GoodsService goodsService;

    // 分页获取商品信息(后台商品管理)
    @GetMapping("/list")
    public Result<PageDTO<GoodsDTO>> getGoodsPage(PageRequest request) {
        PageDTO<GoodsDTO> goodsPage = goodsService.getGoodsPage(request);
        return Result.ok(goodsPage);
    }

    // 新增商品(后台商品管理)
    @PostMapping()
    public Result<String> addGoods(@RequestBody GoodsCommand command) {
        goodsService.addGoods(command);
        return Result.ok();
    }
    // 更新商品(后台商品管理)
    @PutMapping
    public Result<String> updateGoods(@RequestBody GoodsCommand command){
        goodsService.updateGoods(command);
        return Result.ok();
    }
    // 删除商品(后台商品管理)
    @DeleteMapping("{goodsId}")
    public Result<DeleteGoodsOperateDTO> deleteGoods(@PathVariable Long goodsId){
        DeleteGoodsOperateDTO deleteGoodsOperateDTO = goodsService.deleteGoods(goodsId);
        return Result.ok(deleteGoodsOperateDTO);
    }
    // 批量删除指定商品(后台商品管理)
    @DeleteMapping("/selected")
    public Result<List<DeleteGoodsOperateDTO>> deleteGoodsSelected(@RequestBody BatchDeleteCommand command){
        List<DeleteGoodsOperateDTO> deleteGoodsOperateDTOS = goodsService.deleteGoodsSelected(command);
        return Result.ok(deleteGoodsOperateDTOS);
    }
    // 更新商品上下架状态(后台商品管理)
    @PutMapping("/status/{goodsId}")
    public Result<String> updateGoodsStatus(@PathVariable Long goodsId,@RequestParam Integer status){
        goodsService.updateGoodsStatus(goodsId,status);
        return Result.ok();
    }
}
